﻿using System;
using System.Collections.Generic;
using Jayden.Dll.Web.Enums;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;
using Jayden.Dll.Web.HtmlControls.Interfaces;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Script : HtmlElement, WithType, WithSrc, WithAsync, WithDefer
	{
		public Script() : base(ScriptDescription.Instance) { }
		public Script(string src, string type = null)
			: this()
		{
			if (src != null)
				Src = src;
			if (type != null)
				Type = type;
		}

		public string Src { get { return this["src"]; } set { this["src"] = value; } }
		public string Type { get { return this["type"]; } set { this["type"] = value; } }

		public bool Defer { get { return GetAttributeBool("defer"); } set { SetAttribute("defer", value); } }
		public bool Async { get { return GetAttributeBool("async"); } set { SetAttribute("async", value); } }
		public string Charset { get { return this["charset"]; } set { this["charset"] = value; } }
	}
	public class ScriptDescription : HtmlElementDescription
	{
		public static readonly ScriptDescription Instance = new ScriptDescription();
		private ScriptDescription() : base("script", HtmlVersion.Html4, true, true) { }
		public override string Description { get { return "enables dynamic script and data blocks to be included in documents."; } }
		public override Type ControlType { get { return typeof(Script); } }
		public override bool IsPhrasingElement { get { return true; } }
		public override bool IsMetaDataElement { get { return true; } }
		public override IEnumerable<HtmlElementDescription> PermittedElements { get { yield break; } }
		public override bool AllowFlowContent { get { return false; } }
		public override bool AllowPhrasingContent { get { return false; } }
	}
	public class NoScript : HtmlElement
	{
		public NoScript() : base(NoScriptDescription.Instance) { }
	}
	public class NoScriptDescription : HtmlElementDescription
	{
		public static readonly NoScriptDescription Instance = new NoScriptDescription();
		private NoScriptDescription() : base("noscript", HtmlVersion.Html4, true, true) { }
		public override string Description { get { return "present different markup to user agents that don’t support scripting, by affecting how the document is parsed."; } }
		public override Type ControlType { get { return typeof(NoScript); } }
		public override bool IsPhrasingElement { get { return true; } }
		public override bool IsMetaDataElement { get { return true; } }
	}
}
